import React from "react";
import { createBrowserRouter } from "react-router-dom";
import ManageLayout from "../layouts/ManageLayout";
import MainLayout from "../layouts/MainLayout";
import QuestionLayout from "../layouts/QuestionLayout";
import Home from "../pages/entrance/Home";
import Login from "../pages/entrance/Login";
import Register from "../pages/entrance/Register";
import NoFind from "../pages/entrance/NoFind";
import List from "../pages/manage/List";
import Trash from "../pages/manage/Trash";
import Star from "../pages/manage/Star";
import Edit from "../pages/question/Edit";
import Stat from "../pages/question/Stat";

const router = createBrowserRouter([
  {
    path: "/",
    element: <MainLayout />,
    children: [
      {
        path: "/",
        element: <Home />,
      },
      {
        path: "login",
        element: <Login />,
      },
      {
        path: "register",
        element: <Register />,
      },
      {
        path: "manage",
        element: <ManageLayout />,
        children: [
          {
            path: "list",
            element: <List />,
          },
          {
            path: "star",
            element: <Star />,
          },
          {
            path: "trash",
            element: <Trash />,
          },
        ],
      },

      {
        path: "*", //兜底的页面
        element: <NoFind />,
      },
    ],
  },
  {
    path:"question",
    element:<QuestionLayout/>,
    children:[
      {
        //动态路由id
        path: "edit/:id",
        element: <Edit/>
      },
      {
        path: "stat/:id",
        element: <Stat/>
      }
    ]
  },
]);

export default router;


export const HOME_PATH  = "/";

export const LOGIN_PATH = "/login";
export const REGISTER_PATH = "/register";

export const MANAGE_LIST_PATH = "/manage/list";

export const MANAGE_TRASH_PATH ="/manage/trash";
export const MANAGE_TART_PATH ="/manage/star";
//这里的路由是带参数的
export const QUESTION_EDIT_PATH ="/question/edit/";
export const QUESTION_STAT_PATH ="/question/stat/";


 export  function  isLoginOrRegister(pathname:string){
           if ([REGISTER_PATH,LOGIN_PATH].includes(pathname)) {
             return true;
           }
           return false;
}

export  function  isNoNeedUserInfo(pathname:string){
  if([REGISTER_PATH,LOGIN_PATH,HOME_PATH].includes(pathname)) {
    return true;
  }
  return false;
}
